﻿using System.Collections.Generic;
using System.Xml;

namespace Quail.Silverlight
{
    /// <summary>
    /// Wraps the Silverlight Accordion control
    /// </summary>
    public class SlvAccordion : SlvControl
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SlvAccordion"/> class.
        /// </summary>
        public SlvAccordion()
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SlvAccordion"/> class.
        /// </summary>
        /// <param name="container">The container for the control.</param>
        /// <param name="selector">The selector.</param>
        public SlvAccordion(SlvControlContainer container, string selector)
            : base(container, selector)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="SlvAccordion"/> class.
        /// </summary>
        /// <param name="control">The control.</param>
        public SlvAccordion(SlvControl control)
            : base(control)
        {
        }

        /// <summary>
        /// Gets the list of selected indices
        /// </summary>
        public IList<int> SelectedIndices
        {
            get
            {
                var x = GetPropertyValueArray("SelectedIndices");
                var result = new List<int>();

                foreach (var i in x)
                {
                    result.Add(int.Parse(i));
                }

                return result;
            }
        }

        /// <summary>
        /// Gets or sets the currently selected index
        /// </summary>
        public int SelectedIndex
        {
            get { return int.Parse(GetPropertyValue("SelectedIndex")); }
            set { SetPropertyValue("SelectedIndex", value.ToString()); }
        }

        /// <summary>
        /// Gets or sets the current value
        /// </summary>
        public string Value
        {
            get { return GetPropertyValue("Value"); }
            set { SetPropertyValue("Value", value); }
        }

        public SlvControl Item
        {
            get
            {
                return new SlvControl(this, "Content");
            }
        }

        /// <summary>
        /// Gets an array of values from the list
        /// </summary>
    	public string[] Values
    	{
    		get
    		{
    		    return GetPropertyValueArray("Values");
    		}
    	}

        /// <summary>
        /// Gets the array of values as an Xml string
        /// </summary>
		public XmlDocument ValuesAsXml
		{
			get
			{
				var dom = new XmlDocument();

			    dom.LoadXml(GetPropertyValue("ValuesAsXml"));
				
				return dom;
			}
		}
    }
}
